<template>
  <div v-loading="loading">
    <h4 class="mb-5 text-center">快捷入口</h4>
    <ul class="list-unstyled">
      <li v-for="(item, index) in todoList" :key="index">
        <router-link class="todo-link" :to="item.url">
          <span>{{ item.name }}</span>
          <span class="float-right text-danger">{{ item.num }}</span>
        </router-link>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      loading: false,
      todoList: [
        {
          name: '推荐项目',
          num: 0,
          url: { name: 'taskPrelim', query: { status: 2 } },
        },
        {
          name: '调查项目',
          num: 0,
          url: { name: 'taskPrelim', query: { status: 1 } },
        },
        {
          name: '登记项目',
          num: 0,
          url: { name: 'taskRegister', query: { status: 1 } },
        },
        {
          name: '临近还款',
          num: 0,
          url: { name: 'warning_list', query: { status: 0, taskStatus: 0 } },
        },
        {
          name: '结息情况',
          num: 0,
          url: { name: 'warning_interest', query: { status: 0, taskStatus: 1 } },
        },
        {
          name: '异常提示',
          num: 0,
          url: { name: 'warning_abnormal', query: { status: 0, taskStatus: 1 } },
        },
      ],
      numSum: 0,
    }
  },
  computed: {
    userId() {
      return this.$store.getters.user.userId
    },
    clientId() {
      return this.$store.getters.org.clientId
    },
  },
  watch: {},
  created() {
    this.getData()
  },
  mounted() {},
  methods: {
    async getData() {
      this.loading = true
      let [res1, err1] = await this.$utils.promise(
        this.$api.getData('credit', 'credit_project_total_bank_view', {
          'client_id.eq': this.clientId,
        })
      )

      this.loading = false

      if (err1) {
        return this.$message.error('请求数据失败，请重试！')
      }

      if (res1 && res1.data && res1.data.length) {
        this.todoList[0].num = res1.data[0].no_claim_total || 0
        this.todoList[1].num = res1.data[0].yes_census || 0
        this.todoList[2].num = res1.data[0].register_total || 0
        this.todoList[3].num = res1.data[0].near_repay || 0
        this.todoList[4].num = res1.data[0].interest_total || 0
        this.todoList[5].num = res1.data[0].ex_total || 0
      }

      for (let p of this.todoList) {
        this.numSum += Number(p.num)
      }
    },
  },
}
</script>
<style scoped lang="scss">
.todo-link {
  display: block;
  padding: 1rem;
  background-color: #f2f2f2;
  color: #999;
  border-radius: 0.15rem;
  margin-bottom: 1rem;
  border: 1px solid #f2f2f2;

  &:hover {
    background-color: #fff;
    border-color: $primary;
    border-color: var(--primary);
  }
}
</style>
